/*
 *  $Id: BecomeLich.cs 1221 2010-11-30 16:54:52Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Darkness.Spells {
    public class BecomeLich: SelfEnchantmentCard {
        public BecomeLich(): base("001_d_s_become_lich") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Darkness;
            Value = 100;
            AddManaCost(ElementType.Darkness, 3);
        }

        private int _mana;

        protected override void DoAction(TargetArgs<int> args) {
            _mana = args.Player.GetMana(ElementType.Darkness);
            args.Player.DecrementMana(ElementType.Darkness, _mana);
            base.DoAction(args);
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new BecomeLichAffect(_mana);
        }

        private class BecomeLichAffect: EnchantmentAffect<BecomeLich> {
            private static readonly Languages.CardPhrase<BecomeLich> AfterDispell = new Languages.CardPhrase<BecomeLich>("affect.desc.dispelled");

            private int _value;
            private bool _dispelled;
            private TimeAffect _time;

            public BecomeLichAffect(int value): base(true) {
                DefaultDescription = true;
                _value = value;
                _dispelled = false;
                _time = null;
                Add(new Affects.ModMinHealth(-value));
                Add(new Affects.Immune(DamageType.Health));
            }

            public override Languages.Phrase Description {
                get { return _dispelled ? AfterDispell.Phrase : base.Description; }
            }
            public override string DescriptionText {
                get { return Description.GetText(_value, _time != null ? (_time.Phases+3)/4 : 0); }
            }

            public override bool IsEnded {
                get { return _dispelled && (_time != null ? _time.IsEnded : true); }
            }

            public override void Dispell() {
                ResetAffects();
                if (_time != null) Remove(_time);
                _time = new TimeAffect(8);
                Add(_time);
                _dispelled = true;
                SetAffects();
                UpdateDescription();
            }

            public override Affect Clone() {
                return new BecomeLichAffect(_value);
            }
        }
    }
}
